package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.pojo.order.Order;
import com.qingcheng.service.order.AlipayService;
import com.qingcheng.service.order.OrderService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@RestController
@RequestMapping("/alipay")
public class AlipayController {

    @Reference
    private OrderService orderService;

    @Reference
    private AlipayService alipayService;



    @RequestMapping("/createNative")
    public Map createAlipayNative(String orderId ){
        Order order = orderService.findById(orderId);
        //1.获取当前登录用户
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        //第一个参数订单号,第二个参数 money
        Map map = alipayService.createNative(orderId, order.getPayMoney()+"");
        //返回一个包含订单号的map集合  code_url
        return map;
    }

    //支付宝回调
    @RequestMapping("/alipayCallBack")
    public String alipayCallBack(HttpServletRequest request) {
        System.out.println("===================");

        Map requestParams = request.getParameterMap();
        alipayService.notifyLogic(requestParams);

        return "success";

    }





}
